home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / doc / efun / sscanf < prev    next >
Text File  |  2001-05-16  |  3KB  |  68 lines

  1. SYNOPSIS
  2.         int sscanf(string str, string fmt, mixed var1, mixed var2, ...)
  3.  
  4. DESCRIPTION
  5.  
  6.         Parse a string str using the format fmt. fmt can contain
  7.         strings seperated by %d and %s. Every %d and %s corresponds to
  8.         one of var1, var2, ... .
  9.  
  10.         The match operators in the format string have one of these
  11.         formats:
  12.           %[!|~][<size>[.<minmatch>]]<type>        
  13.  
  14.         <type> may be:
  15.            d: matches any number.
  16.            D: matches any number.
  17.            U: matches any unsigned number.
  18.            s: matches any string.
  19.            %: matches the % character.
  20.            t: matches whitespace (spaces and tab characters), but does
  21.               not store them (the simple ' ' matches just spaces and
  22.               can't be given a size specification).
  23.  
  24.         <size> is the expected field size, <minmatch> the demanded
  25.         minimal match length (defaults are 0 for strings and 1 for
  26.         numbers). Each of these both may be specified numerically, or
  27.         as '*' - then the value of the variable at the current place
  28.         in the argument list is used.
  29.         Specifying ! will perform the match, but neither store the
  30.         result nor count the match.
  31.         Specifying ~ will perform and count the match, but not store
  32.         the result.
  33.  
  34.         If the %s specifier is not at the end of the format string,
  35.         it is matched only if the following character(s) or format
  36.         is found, too. See below for an example.
  37.  
  38.         The difference between %d and %D/%U is that the latter will abort
  39.         an immediately preceeding %s as soon as possible, whereas the
  40.         former will attempt to make largest match to %s first.
  41.         %D/%U will still not skip whitespace, use %.0t%D to skip optional
  42.         whitespace.
  43.  
  44.         The number of matched arguments will be returned.
  45.  
  46.         The function sscanf is special, in that arguments are passed
  47.         by reference automatically.
  48.  
  49. EXAMPLE
  50.         string who, what;
  51.         if (sscanf("throw frisbee to rover",
  52.            "throw %s to %s", what, who) != 2)
  53.            write("Usage: throw <what> to <who>\n");
  54.         else
  55.            write("You throw a "+what+" to "+who+" to get his attention.\n");
  56.  
  57.         sscanf("ab", "%s%s", who, what)
  58.           ==> result 2, who = "", what = "ab"
  59.  
  60.         sscanf("ab", "%s %s", who, what)
  61.           ==> result 0, who = 0, what = 0
  62.  
  63.         sscanf("ab ", "%s %s", who, what)
  64.           ==> result 2, who = "ab", what = ""
  65.  
  66. SEE ALSO
  67.         extract(E), explode(E), regexp(E)
  68.